package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController{

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation(value = "分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProject>> getByPage(@ApiParam(value = "护理项目名称") String name,
                                                                  @ApiParam(value = "当前页码")
                                                                  @RequestParam(defaultValue = "1") Integer pageNum,
                                                                  @ApiParam(value = "每页显示条数") @RequestParam(defaultValue = "10") Integer pageSize,
                                                                  @ApiParam(value = "状态（0：禁用，1：启用）") Integer status) {

        PageResponse<NursingProjectVo> nursingProjectPageInfo = nursingProjectService.getByPage(name, pageNum, pageSize, status);
        return success(nursingProjectPageInfo);
    }

    @PostMapping
    public ResponseResult add(
            @ApiParam(value = "护理项目数据传输对象")
            @RequestBody NursingProjectDto nursingProjectDto
            ) {
        nursingProjectService.add(nursingProjectDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> getById(@ApiParam("id") @PathVariable("id") Long id) {
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return success(nursingProjectVo);
    }

    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.update(nursingProjectDto);
        return success();
    }
}
